//
//  segTarget_MobClick.m
//  commonThirds
//
//  Created by 山刘 on 2019/4/16.
//  Copyright © 2019年 山刘. All rights reserved.
//

#import "SEGTarget_MobClick.h"
#import <UMCommon/UMCommon.h>
#import <UMCommon/MobClick.h>
//#import <UMCommonLog/UMCommonLogHeaders.h>

#if __has_include(<Commom/Aspects.h>)
#import <Commom/Aspects.h>
#else
#import "Aspects.h"
#endif

@implementation SEGTarget_MobClick
/**
 设置开始进行有盟统计页面埋点记录
 */
-(void)segAction_startMobAnalytics:(NSDictionary*)params {
    //开发者需要显式的调用此函数，日志系统才能工作
//    [UMCommonLogManager setUpUMCommonLogManager];
#ifdef DEBUG
    [UMConfigure setLogEnabled:YES];//设置打开日志
    [UMConfigure initWithAppkey:[params valueForKey:@"appKey"] channel:@"Debug"];
#else
    [UMConfigure setLogEnabled:NO];
    [UMConfigure initWithAppkey:[params valueForKey:@"appKey"] channel:@"App Store"];
#endif

    
    [UIViewController aspect_hookSelector:@selector(viewWillAppear:)
                              withOptions:AspectPositionBefore
                               usingBlock:^(id<AspectInfo> info) {
                                   [MobClick beginLogPageView:NSStringFromClass([[info instance] class])];
                                   
                               } error:NULL];
    
    [UIViewController aspect_hookSelector:@selector(viewWillDisappear:)
                              withOptions:AspectPositionBefore
                               usingBlock:^(id<AspectInfo> info) {
                                   [MobClick endLogPageView:NSStringFromClass([[info instance] class])];
                               } error:NULL];
}
@end
